<template>
  <div>
    <el-row>
      <el-card>
        <el-form>
          <el-row>
            <el-col :span="8"
              ><div class="grid-content bg-purple">
                <el-form-item label="运输任务编号:">
                  <el-input
                    style="width: 70%"
                    v-model="formData.id"
                    placeholder="请输入运输任务编号"
                  ></el-input>
                </el-form-item></div
            ></el-col>
            <el-col :span="8"
              ><div class="grid-content bg-purple-light">
                <el-form-item label="起始地机构:">
                  <el-select
                    v-model="formData.startAgencyId"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in formatData1(options1)"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                      style="display: none"
                    ></el-option>
                    <el-tree
                      highlight-current
                      node-key="id"
                      :data="options1"
                      :props="defaultProps"
                      @node-click="handleNodeClick"
                      :current-node-key="value"
                      :expand-on-click-node="expandOnClickNode"
                    ></el-tree>
                  </el-select>
                </el-form-item></div
            ></el-col>
            <el-col :span="8"
              ><div class="grid-content bg-purple">
                <el-form-item label="目的地机构:">
                  <el-input style="width: 70%"></el-input>
                </el-form-item></div
            ></el-col>
          </el-row>
          <el-row>
            <el-col :span="8"
              ><div class="grid-content bg-purple-light">
                <el-form-item label="回车时间:">
                  <el-date-picker
                    style="width: 70%"
                    v-model="value1"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  >
                  </el-date-picker>
                </el-form-item></div
            ></el-col>
            <el-col :span="8"
              ><div class="grid-content bg-purple-light">
                <el-form-item label="车辆是否可用:">
                  <el-select
                    v-model="formData.isAvailable"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item></div
            ></el-col>
            <el-col :span="8">
              <el-button type="primary" @click="submit">搜索</el-button>
              <el-button @click="chongzhi">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-card>
        <el-col>
          <el-table
            border
            stripe
            style="text-align: center; margin-top: 15px; margin-bottom: 20px"
            :data="tableDate"
          >
            <el-table-column
              prop="transportTaskId"
              label="运输任务编号"
            ></el-table-column>
            <el-table-column
              prop="startAgencyName"
              label="起始地机构"
            ></el-table-column>
            <el-table-column
              prop="endAgencyName"
              label="目的地机构"
            ></el-table-column>
            <el-table-column
              prop="transportOrderNumber"
              label="运单数量"
            ></el-table-column>
            <el-table-column
              prop="outStorageTime"
              label="出车时间"
            ></el-table-column>
            <el-table-column prop="intoStorageTime" label="回车时间">
            </el-table-column>
            <el-table-column
              prop="licensePlate"
              label="车牌号码"
            ></el-table-column>
            <el-table-column label="车辆是否可用">
              <template #default="{ row }">
                <span :class="row.isAvailable ? 'span2' : 'span1'"></span>
                <span> {{ row.isAvailable ? "可用" : "不可用" }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="60">
              <template #default>
                <el-button style="color: rgb(65, 158, 255)" type="text"
                  >查看</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-card>
    </el-row>
  </div>
</template>

<script>
import { gethuicheListApi, getTreeListApi } from "@/api/cheAdmin";

export default {
  data() {
    return {
      value1: "",
      value: 6,
      expandOnClickNode: true,
      formData: [],
      tableDate: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
      options: [
        {
          value: null,
          label: "全部",
        },
        {
          value: false,
          label: "不可用",
        },
        {
          value: true,
          label: "可用",
        },
      ],
      options1: [],
      pages: {
        page: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.gethuicheListInfo();
  },
  methods: {
    submit() {},
    handleNodeClick() {},
    chongzhi() {},
    formatData1(data) {
      let options = [];
      data.forEach((item) => {
        options.push({ label: item.label, value: item.id });
        if (item.children) {
          item.children.forEach((items) => {
            options.push({ label: items.label, value: items.id });
            if (items.children) {
              items.children.forEach((itemss) => {
                options.push({ label: itemss.label, value: itemss.id });
                if (itemss.children) {
                  itemss.children.forEach((itemsss) => {
                    options.push({ label: itemsss.label, value: itemsss.id });
                  });
                }
              });
            }
          });
        }
      });
      return options;
    },
    async gethuicheListInfo() {
      const res = await gethuicheListApi(this.pages);
      console.log(res.data.data);
      this.tableDate = res.data.data.items;
      this.total = +res.data.data.counts;
      const res2 = await getTreeListApi();
      // console.log(res2.data.data);
      console.log(JSON.parse(res2.data.data));
      this.options1 = JSON.parse(res2.data.data);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-form-item {
  ::v-deep .el-form-item__label {
    width: 100px;
  }
}
.el-row {
  .el-pagination {
    text-align: center;
  }
}
.el-table .cell .span1 {
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: red;
  border-radius: 50%;
  margin-right: 4px;
}
.el-table .cell .span2 {
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: rgb(29, 199, 121);
  border-radius: 50%;
  margin-right: 4px;
}
</style>
